using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DocLibApp
{
    public partial class FormBatchProcess : FormBase
    {
        public FormBatchProcess()
        {
            InitializeComponent();
            SetupGUI();
        }

        private void SetupGUI()
        {
            util.SetupCombo(cboCategory, FormMain.DocLibStaticValueList, "DOC_CATEGORY");
            util.SetupCombo(cboDocType, FormMain.DocLibStaticValueList, "DOC_TYPE");
            util.SetupCombo(cboOwner, FormMain.DocLibStaticValueList, "DOC_OWNER");
            util.SetupCombo(cboImportance, FormMain.DocLibStaticValueList, "DOC_IMPORTANCE");
            util.SetupCombo(cboDocLocation, FormMain.DocLibStaticValueList, "DOC_LOCATION");
        }

        public void AddDocumentToList(string doc_id)
        {
            if (!lsv_DocList.IsItemAlreadyInList(doc_id))
            {
                System.Collections.Hashtable ht = doc_operation.GetDocumentInformation(doc_id);
                ListViewItem aNewItem = new ListViewItem(ht["TITLE"].ToString());
                aNewItem.SubItems.Add(doc_id);

                aNewItem.Tag = doc_id;

                lsv_DocList.Items.Add(aNewItem);
            }
        }

        private void btnApplyChanges_Click(object sender, EventArgs e)
        {
            ApplyChanges();
        }

        private void ApplyChanges()
        {
            if (lsv_DocList.Items.Count > 0 && ConfirmToProcess("Are you sure you wanted to update document info?"))
            {
                System.Collections.Hashtable ht = SaveDataToHashFromControls(groupBox_DocumentInfo.Controls);

                List<string> FileList = lsv_DocList.SaveItemsIntoStringList();

                ShowMessage(doc_operation.ApplyBatchChangeToDocuments(FileList, ht));

                this.Close();
            }
        }

        private void btnPickTemplate_Click(object sender, EventArgs e)
        {
            string template_id = PickTemplate();

            if (!string.IsNullOrEmpty(template_id))
            {
                System.Collections.Hashtable ht = doc_template.Get_Template_Fields(template_id);
                LoadDataFromHashToControls(groupBox_DocumentInfo.Controls, ht);
            }
        }
    }
}